import React, { lazy, Suspense } from 'react';
// lazy  是一个方法, 引入组件的方法, 函数, 以懒加载的形式引入
// Suspense 是一个组件, 可以指定加载组件时的动画,
import { Route, Redirect, Switch } from 'react-router-dom';
import Loading from '../components/Loading';
// 引入登录页
const Login = lazy(() => import('../views/login/Index'));
// 引入首页
const Dashboard = lazy(() => import('../views/dashboard/Dashboard'))
const Index = () => {
    return (
        //Suspense作用: 当路由匹配的组件还没有显示之前, 显示Loading组件
        <Suspense fallback={<Loading></Loading>}>
            <Switch>
                <Route path='/login' component={Login}></Route>
                <Route path='/dashboard' component={Dashboard}></Route>
                <Redirect from='/' to='/login' exact></Redirect>
            </Switch>
        </Suspense>
    );
}

export default Index;